import { isFunction } from '@/utils/is'
import {
  defineComponent,
  defineAsyncComponent,
  type DefineComponent,
  type AsyncComponentLoader,
  type AsyncComponentOptions,
} from 'vue'

type Component = DefineComponent<any, any, any>

export const W = (
  Component: AsyncComponentLoader | AsyncComponentOptions | Component,
  name: string,
) => {
  return defineComponent({
    name,
    setup() {
      const Comp =
        isFunction(Component) || (Component as AsyncComponentOptions).loader
          ? defineAsyncComponent(Component as AsyncComponentLoader | AsyncComponentOptions)
          : Component

      return () => <Comp />
    },
  })
}
